
include sources.mk
BUILD_DIR =output

OBJS+=$(addprefix $(BUILD_DIR)/, $(notdir $(SRC_C:.c=.o)))
OBJS+=$(addprefix $(BUILD_DIR)/, $(notdir $(SRC_S:.S=.o)))

OBJS1+= $(notdir $(SRC_C:.c=.o))
OBJS1+=$(notdir $(SRC_S:.S=.o))

# CFLAGS+=-march=armv5te -mtune=arm926ej-s -mfloat-abi=soft -marm -mno-thumb-interwork -g -ggdb -Wall -fdata-sections -ffunction-sections -ffreestanding -std=gnu99
# CFLAGS+=-D__ARM32_ARCH__=5 -D__ARM926EJS__
# CFLAGS+=-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1 -DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD=1
# CFLAGS+=-fomit-frame-pointer -Wall -fverbose-asm -Os

DEVICE = -mcpu=arm926ej-s -ffunction-sections -fdata-sections

CFLAGS +=$(DEVICE) -Wall


# DRAM size: 32M for F1C100s, 64M for F1C200s
DRAM_SIZE = 64
# LDFLAGS+=-Wl,--defsym=DRAM_SIZE=$(DRAM_SIZE),-Map=$(BUILD_DIR)/$(TARGET).map,--cref,--no-warn-mismatch
# LDFLAGS += -nostartfiles -Xlinker --gc-sections

LDFLAGS +=$(DEVICE) -Wl,--gc-sections,-Map=rtthread.map,-cref -Tlink.lds

LIBS+= \
#-lgcc -lm -lc_nano



ELF=$(BUILD_DIR)/$(TARGET).elf
BIN =$(BUILD_DIR)/$(TARGET).bin
vpath %.c $(sort $(dir $(SRC_C)))
vpath %.S $(sort $(dir $(SRC_S)))

.PHONY : all clean test download
 
all: $(BUILD_DIR) $(OBJS) $(ELF) $(BIN)  

$(BUILD_DIR):
	mkdir $@

download:$(BIN) 
	xfel spinor write 0x10000 $(BIN)

$(BUILD_DIR)/%.o:%.c
	$(CC) -c $(CFLAGS) $< $(INCLUDE) -o $@

$(BUILD_DIR)/%.o:%.S
	@echo compile ASM file $<
	$(CC) $(CFLAGS) -c  $< $(INCLUDE) -o $@

$(ELF):$(OBJS)
	$(CC) $(LDFLAGS) $^ $(LIBS)  -o $@

$(BIN):$(ELF)
	$(CP) -O binary -S $< $@ 


clean:
	rm -rf $(BUILD_DIR)

test :$(BUILD_DIR)
#	@echo .c= $(SRC_C) 
#	@echo testc=$(TEST_C)
#	@echo .S=$(SRC_S)
#	@echo inc=$(INCLUDE)
	@echo objs=$(OBJS1)
#	@echo cflgs=$(CFLAGS)
#	@echo ld=$(LDCRIPT)
#	@echo ldflag=$(LDFLAGS)
#	gcc $(TEST_C) -o $(BUILD_DIR)/testgcc

d:
	make clean
	make all  -j4 
#   make dis
	make download
	